<?php

require_once(WSB_XTENSION_PATH . 'mediaplayer/models/DbTable/Table.php');

class Mediaplayer_IndexController extends WSB_Xtension_Content
{

	private $_width;
	private $_height;

	public function init()
	{
		$config = $this->getConfiguration();
		$this->_width = isset($config->_width) ? $config->_width : 320 ;
		$this->_height = isset($config->_height) ? $config->_height : 240 ;
		parent::init();
	}

	public function indexAction()
	{
		$table = $this->getTable();
		$where = $table->getAdapter()->quoteInto('id=?', $this->_container->item_id);
		$row = $table->fetchRow($where);
		if($row instanceof WSB_Db_Row) {
			if(is_file(WSB_PATH . $row->file_path)) {
				$this->_view->swfobjectPath = WSB_URL . 'WSB/xtensions/mediaplayer/res/';
				$this->_view->width = empty($row->width) ? $this->_width : $row->width ;
				$this->_view->height = empty($row->height) ? $this->_height : $row->height ;
				$this->_view->file_path = WSB_URL . $row->file_path;
				$this->addContent(sprintf('<div class="mediaplayer mediaplayer-%s mediaplayer-layout-%s">', $this->_module->id, intval($row->layout)));
				$this->addContent($this->_view->render('index.phtml'));
				$this->addContent('</div>');
			}
		}
	}

	public function getTable()
	{
		return new Mediaplayer_Model_DbTable_Table();
	}

}
